﻿@{
    ViewBag.Title = "Home Page";
}
<!-- #region name -->
@*<div class="jumbotron">
        <h1>ASP.NET</h1>
        <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
        <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
    </div>

    <div class="row">
        <div class="col-md-4">
            <h2>Getting started</h2>
            <p>
                ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
                enables a clean separation of concerns and gives you full control over markup
                for enjoyable, agile development.
            </p>
            <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
        </div>
        <div class="col-md-4">
            <h2>Get more libraries</h2>
            <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
            <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
        </div>
        <div class="col-md-4">
            <h2>Web Hosting</h2>
            <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
            <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
        </div>
    </div>*@
<!-- #endregion -->

<script type="text/javascript">
    $(function() {
        initTable();


    });

    

    var isedit = false;
    var lasteditRowindex = 0;

    function initTable() {
        $("#tt").datagrid({
            pagination: 'true',
            rownumbers: 'true',
            url: '@Url.Action("Index", "Territories")',
            title: '这是一个测试的数据表',
            pageNumber: 1,
            
            pagePosition: 'top',
            singleSelect: true,
            onDblClickRow: function(rowIndex, rowData) {
                if (isedit == false) {

                    $('#tt').datagrid('beginEdit', rowIndex);
                    lasteditRowindex = rowIndex;
                    isedit = true;
                } else {
                    isedit = false;
                    $('#tt').datagrid('endEdit', lasteditRowindex);
                  
                 
                }


            },
          


            columns: [
                [
                    {
                        field: 'TerritoryID',
                        title: '用户名',
                        
                    },
                    {
                        field: 'TerritoryDescription',
                        title: '密码',
                        editor: {
                            type: 'text'
                        }
                    },
                    {
                        field:'Regions',
                        title: '密码',
                        width:180,
                        editor: {
                            type: 'combobox',
                            options: {
                                    url:'@Url.Action("Regions","Territories")',
                                editable: false,
                                valueField:'RegionID',
                                textField: 'RegionDescription',
                               
                                onLoadSuccess: function () {
                                  
                                    $(this).combobox('setText', '请选择....');
                                }
                            }
                        },
                        formatter: function (value, row, index) {
                            return value.RegionDescription;

                        }
                    },
                    {
                        field: 'action',
                        title: 'Action',
                        width: 70,
                        align: 'center',
                        formatter: function(value, row, index) {
                            if (isedit) {
                                var s = '<a href="#" onclick="saverow(this)">Save</a> ';
                                var c = '<a href="#" onclick="cancelrow(this)">Cancel</a>';
                                return s + c;
                            } else {
                                var e = '<a href="#" onclick="editrow(this)">Edit</a> ';
                                var d = '<a href="#" onclick="deleterow(this)">Delete</a>';
                                return e + d;
                            }
                        }
                    }
                ],
            ],
            onAfterEdit: function (rowIndex, rowData, changes) {


                afteredit(rowIndex, rowData, changes);
            },

        })
        
        ;
    }

    function afteredit(rowIndex, rowData, changes) {
        
        isedit = false;
        //var ss = rowData;
        //var s = changes;
        //var ed = $('#tt').datagrid('getEditors', { index: rowIndex });

        //var productname = $(ed.target).combobox('getText');
        //var value = $(ed.target).combobox('getValue');
        //alert(productname);
        //alert(value);
        var ss = rowData['Regions'];
        $.post('@Url.Action("updata", "Territories")', {
            TerritoryID: rowData['TerritoryID'],
            TerritoryDescription: rowData['TerritoryDescription'],
            RegionID:ss
    }, function (parameters) {
            if (parameters == "ok") {
                //alert("ok");
                initTable();
            }
        });

    };
</script>
<div id="tt">
    
</div>